#------------- User Settings -------------
visible TAP1_USER = T1 #Must be manually set, AUTO does not work. Set to OFF if setting does not exist.
visible TAP2_USER = T2 #Must be manually set, AUTO does not work. Set to OFF if setting does not exist.
visible TAP3_USER = OFF #Must be manually set, AUTO does not work. Set to OFF if setting does not exist.
visible TAP4_USER = OFF #Must be manually set, AUTO does not work. Set to OFF if setting does not exist.
visible O87P_USER = AUTO
visible SLP1_USER = AUTO
visible SLP2_USER = AUTO
visible IRS1_USER = AUTO
visible PCT2_USER = AUTO #Do not set to 0, use OFF instead
visible PCT4_USER = AUTO #Do not set to 0, use OFF instead
visible INOM_USER = AUTO #AUTO is 5 A nominal
visible 4TH_HARM_1 = 0 #Add 4th Harmonic for A-phase (in percent of fundamental)
visible 4TH_HARM_2 = 0 #Add 4th Harmonic for B-phase (in percent of fundamental)
visible 4TH_HARM_3 = 0 #Add 4th Harmonic for C-phase (in percent of fundamental)
#----------- Definitions -----------
TAP1 = TAP1_USER
TAP2 = TAP2_USER
TAP3 = TAP3_USER
TAP4 = TAP4_USER
IRS1 = IF(IRS1_USER = AUTO,IRS1.SET,IRS1_USER)
O87P = IF(O87P_USER = AUTO,O87P.SET,O87P_USER)
SLP1 = IF(SLP1_USER = AUTO,SLP1.SET,SLP1_USER)
SLP2 = IF(SLP2_USER = AUTO,SLP2.Set,SLP2_USER)
PCT2 = IF(PCT2.Set*1.0>0,(IF(PCT2_USER = AUTO,PCT2.Set*1.0,PCT2_USER)),OFF) #Set PCT2 to OFF if PCT2 = FALSE
PCT4 = IF(PCT4.Set*1.0>0,(IF(PCT4_USER = AUTO,PCT4.Set*1.0,PCT4_USER)),OFF) #Set PCT4 to OFF if PCT4 = FALSE
INOM = IF(INOM_USER = AUTO,5,INOM_USER)
OFF = 9999
AUTO = 99999
#--- Standard Equation ---  
SLP_1 = IF(((IRT1<IRS1)AND(!INR1)),SLP1,SLP2) #Define active slope for Diff Element 1
SLP_2 = IF(((IRT2<IRS1)AND(!INR2)),SLP1,SLP2) #Define active slope for Diff Element 2
SLP_3 = IF(((IRT3<IRS1)AND(!INR3)),SLP1,SLP2) #Define active slope for Diff Element 3
Operate_1 = IF(SLP_1=SLP1,(SLP1/100*IRT1),IF(INR1,(SLP2/100*IRT1),(SLP2/100*IRT1+IRS1*((SLP1-SLP2)/100)))) #Operate quantity for Diff Element 1 based on slope
Operate_2 = IF(SLP_2=SLP1,(SLP1/100*IRT2),IF(INR2,(SLP2/100*IRT2),(SLP2/100*IRT2+IRS1*((SLP1-SLP2)/100)))) #Operate quantity for Diff Element 2 based on slope
Operate_3 = IF(SLP_3=SLP1,(SLP1/100*IRT3),IF(INR3,(SLP2/100*IRT3),(SLP2/100*IRT3+IRS1*((SLP1-SLP2)/100)))) #Operate quantity for Diff Element 3 based on slope
S_thresh_1 = MAX(O87P,Operate_1) #Standard threshold for Diff Element 1
S_thresh_2 = MAX(O87P,Operate_2) #Standard threshold for Diff Element 2
S_thresh_3 = MAX(O87P,Operate_3) #Standard threshold for Diff Element 3
#--- Harmonic Restraint ---
HR_thresh_1 = MAX(O87P,IF((PCT2=OFF AND PCT4=OFF),Operate_1,(Operate_1+(100/PCT2*I1F2)+(4TH_HARM_1*IOP1/PCT4)))) #Harmonic Restraint threshold for Diff Element 1
HR_thresh_2 = MAX(O87P,IF((PCT2=OFF AND PCT4=OFF),Operate_2,(Operate_2+(100/PCT2*I2F2)+(4TH_HARM_2*IOP2/PCT4)))) #Harmonic Restraint threshold for Diff Element 2
HR_thresh_3 = MAX(O87P,IF((PCT2=OFF AND PCT4=OFF),Operate_3,(Operate_3+(100/PCT2*I3F2)+(4TH_HARM_3*IOP3/PCT4)))) #Harmonic Restraint threshold for Diff Element 3
#--- Harmonic Blocking ---
2H_1 = (I1F2/IOP1)*100 #Scaled 2nd harmonics for Diff Element 1, compare to PCT2
2H_2 = (I2F2/IOP2)*100 #Scaled 2nd harmonics for Diff Element 2, compare to PCT2
2H_3 = (I3F2/IOP3)*100 #Scaled 2nd harmonics for Diff Element 3, compare to PCT2
4H_1 = 4TH_HARM_1 #4th harmonic for Diff Element 1, compare to PCT4
4H_2 = 4TH_HARM_2 #4th harmonic for Diff Element 2, compare to PCT4
4H_3 = 4TH_HARM_3 #4th harmonic for Diff Element 3, compare to PCT4
IOP_min = 0.05*INOM/MIN(TAP1,MIN(TAP2,MIN(TAP3,TAP4))) #Minimum operate threshold required for Harmonic Blocking

